home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
C64
/
T-TPUG Old Monthly Disks
/
(c)t8.d64
/
hex dec bin.c
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2007-02-04
|
3KB
|
77 lines
5 POKE53280,1:POKE53281,1
6 REM: :
7 REM: HEX - DEC - BIN CONVERTER :
8 REM: BY: BOB SWIFT :
9 REM: :
10 DIMH$(15):FORI=0TO15:READH$(I):NEXTI
20 DATA0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
30 PRINTCHR$(14);"[147][200][197][216] [144]- [196][197][195] [144]- [194][201][206] [144][195][207][206][214][197][210][212][197][210]"
40 PRINT"[215]RITTEN BY: [210].[196]. [211]WIFT, [208].[197]NG.":PRINTTAB(12);"1983 - 03 - 27"
50 PRINT"1[146] - [200]EXADECIMAL [144]TO [196]ECIMAL[144]"
60 PRINT"2[146] - [196]ECIMAL [144]TO [200]EXADECIMAL[144]"
70 PRINT"3[146] - [200]EXADECIMAL [144]TO [194]INARY[144]"
80 PRINT"4[146] - [194]INARY [144]TO [200]EXADECIMAL[144]"
90 PRINT"5[146] - [196]ECIMAL [144]TO [194]INARY[144]"
100 PRINT"6[146] - [194]INARY [144]TO [196]ECIMAL[144]"
110 PRINT"_[146] - [197]XIT [208]ROGRAM"
120 PRINT"[215]HEN IN CONVERTING MODE, PRESS"
130 PRINT"[210][197][212][213][210][206][146] TO RETURN TO [205][197][206][213]."
140 GETA$:IFA$=""THEN140
150 IFA$="1"THENPRINTCHR$(142);"[147]HEXADECIMAL [144]TO DECIMAL":GOTO1000
160 IFA$="2"THENPRINTCHR$(142);"[147]DECIMAL [144]TO HEXADECIMAL":GOTO2000
170 IFA$="3"THENPRINTCHR$(142);"[147]HEXADECIMAL [144]TO BINARY":GOTO3000
180 IFA$="4"THENPRINTCHR$(142);"[147]BINARY [144]TO HEXADECIMAL":GOTO4000
190 IFA$="5"THENPRINTCHR$(142);"[147]DECIMAL [144]TO BINARY":GOTO5000
200 IFA$="6"THENPRINTCHR$(142);"[147]BINARY [144]TO DECIMAL":GOTO6000
210 IFA$="_"THENPRINTCHR$(142);"[147]":END
220 GOTO140
997 REM: :
998 REM: HEXADECIMAL TO DECIMAL :
999 REM: :
1000 A$="":INPUT"INPUT HEX[144]";A$:IFA$=""THEN30
1010 IFLEN(A$)>4THEN30
1020 GOSUB1030:GOTO1070
1030 D=0:FORI=1TOLEN(A$):T$=MID$(A$,LEN(A$)-I+1,1)
1040 FORJ=0TO15:IFT$=H$(J)THEN1060
1050 NEXTJ:GOTO30
1060 D=D+(16^(I-1))*J:NEXTI:D=INT(D):RETURN
1070 PRINTTAB(19);"[145]";INT(D);"":GOTO1000
1997 REM: :
1998 REM: DECIMAL TO HEXADECIMAL :
1999 REM: :
2000 D=-1:INPUT"INPUT DEC[144]";D:D=INT(D):IFD<0ORD>65535THEN30
2010 GOSUB2020:GOTO2060
2020 T=INT(D/4096):A$=H$(T):D=INT(D-T*4096)
2030 T=INT(D/256):A$=A$+H$(T):D=INT(D-T*256)
2040 T=INT(D/16):A$=A$+H$(T):D=INT(D-T*16)
2050 A$=A$+H$(D):RETURN
2060 PRINTTAB(21);"[145]";A$;"":GOTO2000
2997 REM: :
2998 REM: HEXADECIMAL TO BINARY :
2999 REM: :
3000 A$="":INPUT"INPUT HEX[144]";A$:IFA$=""THEN30
3010 IFLEN(A$)>2THEN30
3020 GOSUB1030:GOSUB3040
3030 PRINTTAB(18);"[145]";A$;"":GOTO3000
3040 A$="":FORI=0TO7:IF(DAND2^I)THEN3060
3050 A$="0"+A$:NEXT:RETURN
3060 A$="1"+A$:NEXT:RETURN
3997 REM: :
3998 REM: BINARY TO HEXADECIMAL :
3999 REM: :
4000 A$="":INPUT"INPUT BIN[144]";A$:IFA$=""ORLEN(A$)>8THEN30
4010 GOSUB4020:A$="":GOSUB2040:PRINTTAB(20);"[145]";A$;"":GOTO4000
4020 D=0:FORI=1TOLEN(A$):IFMID$(A$,LEN(A$)-I+1,1)="0"THENNEXT:D=INT(D):RETURN
4030 IFMID$(A$,LEN(A$)-I+1,1)="1"THEND=D+2^(I-1):NEXT:D=INT(D):RETURN
4040 GOTO30
4997 REM: :
4998 REM: DECIMAL TO BINARY :
4999 REM: :
5000 D=-1:INPUT"INPUT DEC[144]";D:D=INT(D):IFD<0ORD>255THEN30
5010 GOSUB3040:PRINTTAB(17);"[145]";A$;"":GOTO5000
5997 REM: :
5998 REM: BINARY TO DECIMAL :
5999 REM: :
6000 A$="":INPUT"INPUT BIN[144]";A$:IFA$=""ORLEN(A$)>8THEN30
6010 GOSUB4020:PRINTTAB(20);"[145]";D;"":GOTO6000